package com.apps.ftapp.activity;

import android.os.Bundle;
import android.widget.TextView;

import com.apps.ftapp.R;
import com.apps.ftapp.model.Statistics;
import com.apps.ftapp.util.Async;
import com.apps.ftapp.util.Constant;
import com.google.gson.Gson;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;


import cz.msebera.android.httpclient.Header;

public class StatisticsActivity extends BaseActivity {

    private TextView zb_buy_num;
    private TextView zb_study_num;
    private TextView sp_buy_num;
    private TextView sp_stufy_num;
    private TextView paper_done_num;
    private TextView subject_done_num;

    private Gson gson = new Gson();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_statistics);

        init();

    }


    private void init() {
        zb_buy_num = findViewById(R.id.zb_buy_num);
        zb_study_num = findViewById(R.id.zb_study_num);
        sp_buy_num = findViewById(R.id.sp_buy_num);
        sp_stufy_num = findViewById(R.id.sp_study_num);
        paper_done_num = findViewById(R.id.paper_done_num);
        subject_done_num = findViewById(R.id.subject_done_num);
        setTitle("统计");
        loaddata();

    }

    private void loaddata() {
        RequestParams params = new RequestParams();
        params.put("token", Constant.token);
        params.put("userId", Constant.uid);
        Async.post("my/tongji", params, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                if (statusCode == 200) {
                    Statistics data = gson.fromJson(new String(responseBody), Statistics.class);
                    zb_buy_num.setText(data.getZhibo_buy_shuliang() + "个");
                    zb_study_num.setText(data.getZhibo_study_shuliang() + "个");
                    sp_buy_num.setText(data.getShipin_buy_shuliang() + "个");
                    sp_stufy_num.setText(data.getShipin_study_shuliang() + "个");
                    paper_done_num.setText(data.getShijuan_yizuo() + "个");
                    subject_done_num.setText(data.getTiku_yizuo() + "个");

                }
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

            }

            @Override
            public void onFinish() {

            }
        });
    }

}
